<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.3.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/myblog/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/myblog/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/myblog/images/favicon-16x16.png">
  <link rel="mask-icon" href="/myblog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/myblog/css/main.css">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Monda:300,300italic,400,400italic,700,700italic%7CRoboto+Slab:300,300italic,400,400italic,700,700italic%7CNoto+Serif+SC:300,300italic,400,400italic,700,700italic%7CAmita:300,300italic,400,400italic,700,700italic%7CMontserrat:300,300italic,400,400italic,700,700italic%7CPT+Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha256-AbA177XfpSnFEvgpYu1jMygiLabzPCJCRIBtR5jGc0k=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"wang-chen1119.gitee.io","root":"/myblog/","images":"/myblog/images","scheme":"Pisces","darkmode":false,"version":"8.13.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":true,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/myblog/js/config.js"></script>

    <meta name="description" content="虚拟存储器管理 概述局部性原理:first_quarter_moon_with_face:程序在执行过程中呈现局部性原理">
<meta property="og:type" content="blog">
<meta property="og:title" content="操作系统学习笔记(六):虚拟存储器管理">
<meta property="og:url" content="http://wang-chen1119.gitee.io/myblog/2022/10/28/%E8%99%9A%E6%8B%9F%E5%AD%98%E5%82%A8%E5%99%A8%E7%AE%A1%E7%90%86/index.html">
<meta property="og:site_name" content="Yorn&#39;s Notes">
<meta property="og:description" content="虚拟存储器管理 概述局部性原理:first_quarter_moon_with_face:程序在执行过程中呈现局部性原理">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://image-1305623006.cos.ap-nanjing.myqcloud.com/img/202210281348066.png">
<meta property="article:published_time" content="2022-10-28T05:57:30.717Z">
<meta property="article:modified_time" content="2022-10-28T06:21:53.419Z">
<meta property="article:author" content="yorn">
<meta property="article:tag" content="操作系统">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://image-1305623006.cos.ap-nanjing.myqcloud.com/img/202210281348066.png">


<link rel="canonical" href="http://wang-chen1119.gitee.io/myblog/2022/10/28/%E8%99%9A%E6%8B%9F%E5%AD%98%E5%82%A8%E5%99%A8%E7%AE%A1%E7%90%86/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://wang-chen1119.gitee.io/myblog/2022/10/28/%E8%99%9A%E6%8B%9F%E5%AD%98%E5%82%A8%E5%99%A8%E7%AE%A1%E7%90%86/","path":"2022/10/28/虚拟存储器管理/","title":"操作系统学习笔记(六):虚拟存储器管理"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>操作系统学习笔记(六):虚拟存储器管理 | Yorn's Notes</title>
  






  <noscript>
    <link rel="stylesheet" href="/myblog/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/myblog/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Yorn's Notes</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-首页"><a href="/myblog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-关于"><a href="/myblog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-标签"><a href="/myblog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-分类"><a href="/myblog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E8%99%9A%E6%8B%9F%E5%AD%98%E5%82%A8%E5%99%A8%E7%AE%A1%E7%90%86"><span class="nav-number">1.</span> <span class="nav-text">虚拟存储器管理</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A6%82%E8%BF%B0"><span class="nav-number">1.1.</span> <span class="nav-text">概述</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B1%80%E9%83%A8%E6%80%A7%E5%8E%9F%E7%90%86"><span class="nav-number">1.1.1.</span> <span class="nav-text">局部性原理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%99%9A%E6%8B%9F%E5%AD%98%E5%82%A8%E5%99%A8%E5%AE%9A%E4%B9%89"><span class="nav-number">1.1.2.</span> <span class="nav-text">虚拟存储器定义</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%99%9A%E6%8B%9F%E5%AD%98%E5%82%A8%E7%AE%A1%E7%90%86"><span class="nav-number">1.2.</span> <span class="nav-text">虚拟存储管理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%86%E9%A1%B5%E8%99%9A%E6%8B%9F%E5%AD%98%E5%82%A8%E7%AE%A1%E7%90%86"><span class="nav-number">1.2.1.</span> <span class="nav-text">分页虚拟存储管理</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86"><span class="nav-number">1.2.1.1.</span> <span class="nav-text">基本原理</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BC%BA%E9%A1%B5%E4%B8%AD%E6%96%AD%E6%9C%BA%E6%9E%84"><span class="nav-number">1.2.1.2.</span> <span class="nav-text">缺页中断机构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%9C%B0%E5%9D%80%E5%8F%98%E6%8D%A2%E6%9C%BA%E5%88%B6"><span class="nav-number">1.2.1.3.</span> <span class="nav-text">地址变换机制</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%A1%B5%E9%9D%A2%E7%BD%AE%E6%8D%A2%E7%AE%97%E6%B3%95"><span class="nav-number">1.2.1.4.</span> <span class="nav-text">页面置换算法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D%E7%AD%96%E7%95%A5%E5%92%8C%E5%88%86%E9%85%8D%E7%AE%97%E6%B3%95"><span class="nav-number">1.2.1.5.</span> <span class="nav-text">内存分配策略和分配算法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%B0%83%E9%A1%B5%E7%AD%96%E7%95%A5"><span class="nav-number">1.2.1.6.</span> <span class="nav-text">调页策略</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%8A%96%E5%8A%A8"><span class="nav-number">1.2.1.7.</span> <span class="nav-text">抖动</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%BA%A7%E7%94%9F%E6%8A%96%E5%8A%A8%E7%9A%84%E5%8E%9F%E5%9B%A0"><span class="nav-number">1.2.1.7.1.</span> <span class="nav-text">产生抖动的原因</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E9%A2%84%E9%98%B2%E6%8A%96%E5%8A%A8%E7%9A%84%E6%96%B9%E6%B3%95"><span class="nav-number">1.2.1.7.2.</span> <span class="nav-text">预防抖动的方法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%86%E6%AE%B5%E8%99%9A%E6%8B%9F%E5%AD%98%E5%82%A8%E7%AE%A1%E7%90%86"><span class="nav-number">1.2.2.</span> <span class="nav-text">分段虚拟存储管理</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86-1"><span class="nav-number">1.2.2.1.</span> <span class="nav-text">基本原理</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BC%BA%E6%AE%B5%E4%B8%AD%E6%96%AD%E6%9C%BA%E6%9E%84"><span class="nav-number">1.2.2.2.</span> <span class="nav-text">缺段中断机构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%AE%B5%E7%9A%84%E5%8A%A8%E6%80%81%E8%BF%9E%E6%8E%A5"><span class="nav-number">1.2.2.3.</span> <span class="nav-text">段的动态连接</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%AE%B5%E7%9A%84%E5%85%B1%E4%BA%AB"><span class="nav-number">1.2.2.4.</span> <span class="nav-text">段的共享</span></a></li></ol></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="yorn"
      src="/myblog/uploads/head.jpg">
  <p class="site-author-name" itemprop="name">yorn</p>
  <div class="site-description" itemprop="description">足够专注才能成功</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/myblog/archives/">
          <span class="site-state-item-count">53</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/myblog/categories/">
        <span class="site-state-item-count">13</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/myblog/tags/">
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/wang-chen1119" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wang-chen1119" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:w1905989051@gmail.com" title="E-Mail → mailto:w1905989051@gmail.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license site-overview-item animated" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="https://cdnjs.cloudflare.com/ajax/libs/creativecommons-vocabulary/2020.11.3/assets/license_badges/small/by_nc_sa.svg" alt="Creative Commons"></a>
  </div>


  <div class="links-of-blogroll site-overview-item animated">
    <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://blog.csdn.net/qq_51088445" title="https:&#x2F;&#x2F;blog.csdn.net&#x2F;qq_51088445" rel="noopener" target="_blank">CSDN</a>
        </li>
    </ul>
  </div>

        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <a href="https://github.com/wang-chen1119" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://wang-chen1119.gitee.io/myblog/2022/10/28/%E8%99%9A%E6%8B%9F%E5%AD%98%E5%82%A8%E5%99%A8%E7%AE%A1%E7%90%86/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/myblog/uploads/head.jpg">
      <meta itemprop="name" content="yorn">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Yorn's Notes">
      <meta itemprop="description" content="足够专注才能成功">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="操作系统学习笔记(六):虚拟存储器管理 | Yorn's Notes">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          操作系统学习笔记(六):虚拟存储器管理
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2022-10-28 13:57:30 / 修改时间：14:21:53" itemprop="dateCreated datePublished" datetime="2022-10-28T13:57:30+08:00">2022-10-28</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/myblog/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" itemprop="url" rel="index"><span itemprop="name">操作系统</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>2.4k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>2 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="虚拟存储器管理"><a href="#虚拟存储器管理" class="headerlink" title="虚拟存储器管理"></a>虚拟存储器管理</h1><p><img src="https://image-1305623006.cos.ap-nanjing.myqcloud.com/img/202210281348066.png" alt="image-20220103143403865"></p>
<h2 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h2><h3 id="局部性原理"><a href="#局部性原理" class="headerlink" title="局部性原理"></a>局部性原理</h3><p><strong>:first_quarter_moon_with_face:程序在执行过程中呈现局部性原理</strong></p>
<p>:question:什么是局部性原理</p>
<blockquote>
<p>局部性原理分为时间和空间两方面</p>
<ul>
<li>时间局部性 ：一条指令被执行后，那么它可能很快会再次执行</li>
<li>空间局部性 ：某一个存储单元被访问后，那么与此存储单元相邻的单元很可能被访问</li>
</ul>
</blockquote>
<h3 id="虚拟存储器定义"><a href="#虚拟存储器定义" class="headerlink" title="虚拟存储器定义"></a>虚拟存储器定义</h3><blockquote>
<p>虚拟存储器：</p>
<ol>
<li>把程序的一部分装入内存便可运行程序的存储系统</li>
<li>具有请求调入功能和置换功能</li>
<li>从逻辑上对内存实现扩充</li>
</ol>
</blockquote>
<p>影响虚拟存储器大小的两个因素</p>
<ol>
<li>外存大小 2. 指令中的地址长度</li>
</ol>
<h2 id="虚拟存储管理"><a href="#虚拟存储管理" class="headerlink" title="虚拟存储管理"></a>虚拟存储管理</h2><h3 id="分页虚拟存储管理"><a href="#分页虚拟存储管理" class="headerlink" title="分页虚拟存储管理"></a>分页虚拟存储管理</h3><h4 id="基本原理"><a href="#基本原理" class="headerlink" title="基本原理"></a>基本原理</h4><blockquote>
<p>分页虚拟存储管理方式是在分页系统的基础上增加了请求调页功能和页面置换功能</p>
</blockquote>
<p>分页虚拟存储管理的页表是在原来的基础上发展而来的包括</p>
<ol>
<li>物理块号 ：调入内存时的块号</li>
<li>状态位 ： 表示改页是否已经调入内存</li>
<li>访问位 ：表示该页在内存期间是否被访问过</li>
<li>修改位 ： 表示该页在内存期间是否被修改过，若未修改过则置换该页时就不需要将该页写回外存，否则需要写会外存保证外存中保留的是最新</li>
<li>外存地址 ： 该页在外存上的地址，通常是物理块号</li>
</ol>
<h4 id="缺页中断机构"><a href="#缺页中断机构" class="headerlink" title="缺页中断机构"></a>缺页中断机构</h4><blockquote>
<p>在分页虚拟存储管理系统中，每当要访问的页面不在内存时，便产生一个缺页中断，请求操作系统把所缺页面调入内存</p>
</blockquote>
<p><em>:sailboat:缺页中断与一般中断的区别</em></p>
<ol>
<li>缺页中断在指令执行期间产生和处理中断信号。      通常都是在一条指令执行完毕后去检查是否有中断产生，若有则去响应中断；否则继续执行下一条指令；然而缺页中断是在指令执行期间，发现所要访问的指令或数据不在内存时产生和处理的。</li>
<li>一条指令在执行期间可能产生多次缺页中断</li>
</ol>
<h4 id="地址变换机制"><a href="#地址变换机制" class="headerlink" title="地址变换机制"></a>地址变换机制</h4><blockquote>
<p>分页虚拟存储管理系统中的地址变换机构，在原来的基础上增加了产生和处理缺页中断以及从内存中换出一页等功能</p>
</blockquote>
<p>具体过程：</p>
<p>当用户进程要求访问某一页时，如果该页已经调入内存，那么按照分页存储管理方式中的地址变换过程转换地址；如果改页没有调入到内存中，则产生一缺页中断，系统进入相应的缺页中断处理过程。</p>
<p>中断处理过程： 首先保存当前进程的CPU环境，从外存中找到该页。然后，查看当前内存是否有空闲内存调入该页，如果有则启动I&#x2F;O将该页从外存调入内存，同时修改页表，再按分页存储管理方式的地址变换转换地址；如果内存已满，则按照某种算法选择一页作为淘汰页面调出，腾出空间后再调入。</p>
<p>如果被淘汰的页在内存中已经被修改过，则需将改页写回外存。</p>
<h4 id="页面置换算法"><a href="#页面置换算法" class="headerlink" title="页面置换算法"></a>页面置换算法</h4><blockquote>
<p>页面置换算法:选择需要被淘汰的页面</p>
</blockquote>
<ol>
<li>最佳置换算法(OPT)</li>
</ol>
<p>选择的淘汰页面将是以后永不使用或者是在最长时间内不再访问的页</p>
<p><code>最佳置换算法能保证获得最低的缺页率，但无法预知一个进程在内存的若干个页面中哪一个页面是未来最长时间不再被访问的，因此这种算法是无法实现的，只能作为其他置换算法的衡量标准</code></p>
<ol start="2">
<li><p>先进先出算法(FIFO)</p>
<p> 每次淘汰最先进入内存的页</p>
<p> 简单，易于实现</p>
</li>
<li><p>最近最久未使用算法(LRU)</p>
<p> 淘汰最近一段时间内最少使用的一页</p>
</li>
<li><p>简单Clock算法(最近未使用算法)</p>
<p> 为每页设置一个访问位，再将内存中所有的页面通过连接指针链成一个循环队列，当某页被访问时，访问位置1</p>
<p> 置换算法在选择一页淘汰时只须检查其访问位，如果是0，则选择将该页换出，若为1则重新将它复0，暂不换出</p>
</li>
<li><p>改进型Clock算法</p>
<p> 再将一个页面换出时，如果该页面已经被修改过，需将它重新写到磁盘上。修改过得页面换出时比为修改过得页面开销要大</p>
<p> 所以增加访问位A和修改位M</p>
<p> 可以划分四种类型的页面</p>
<ol>
<li>A&#x3D;0 , M&#x3D;0 —–&gt; 该页即没有被修改也没有被访问为最佳淘汰页</li>
<li>A&#x3D;0 , M&#x3D;1 —–&gt; 该页最近未被访问，但已被修改</li>
<li>A&#x3D;1 , M&#x3D;0 —–&gt; 已被访问，但未被修改</li>
<li>A&#x3D;1 , M&#x3D;1 —–&gt; 已被访问且被修改</li>
</ol>
</li>
</ol>
<p>​       执行过程</p>
<p>​        (1)  从指针所指示的当前位置开始，扫描循环队列，寻找A&#x3D;0,M&#x3D;0的页面将所遇到的第一个页面作为所选中的淘汰页。第一次扫描期间不改变访问位A</p>
<p>​        (2)  如果第一步失败，则开始第二轮扫描寻找A&#x3D;0,M&#x3D;1的第二类页面，将所遇到的第一个这类页面作为淘汰页，在第二轮扫描期间，将所有经过的页面的访问位置置0</p>
<p>​        (3)  如果第二步也失败，则将指针返回最开始的位置，然后重复第一步，如果仍失败，必要时在重复第二步，此时一定能找到被淘汰的页</p>
<h4 id="内存分配策略和分配算法"><a href="#内存分配策略和分配算法" class="headerlink" title="内存分配策略和分配算法"></a>内存分配策略和分配算法</h4><ol>
<li><p>最少物理块数</p>
<p> 保证进程运行所需的最少物理块数</p>
</li>
<li><p>内存分配策略</p>
<p> 分配策略： 固定分配   可变分配</p>
<p> 置换策略： 全局置换   局部置换</p>
<p> 三种内存分配策略</p>
<ol>
<li>固定分配局部置换</li>
<li>可变分配全局置换</li>
<li>可变分配局部置换</li>
</ol>
</li>
<li><p>物理块分配算法</p>
<ol>
<li>平均分配算法</li>
<li>按比例分配算法</li>
<li>考虑优先级的分配算法</li>
</ol>
</li>
</ol>
<h4 id="调页策略"><a href="#调页策略" class="headerlink" title="调页策略"></a>调页策略</h4><ol>
<li><p>请求调页策略</p>
<p> 访问某一页面而该页面不在内存时由操作系统将其调入内存</p>
</li>
<li><p>预调页策略</p>
</li>
</ol>
<p>​       在缺页中断发生之前进行调度，即当一个页面即将被访问之前将其调入内存</p>
<h4 id="抖动"><a href="#抖动" class="headerlink" title="抖动"></a>抖动</h4><h5 id="产生抖动的原因"><a href="#产生抖动的原因" class="headerlink" title="产生抖动的原因"></a>产生抖动的原因</h5><blockquote>
<p>每个进程的大部分时间都用于页面的换进换出，而几乎不能去做任何有效的工作，从而导致发生处理机利用率急剧下降，而趋于零的现象，称此时系统处于抖动状态</p>
</blockquote>
<h5 id="预防抖动的方法"><a href="#预防抖动的方法" class="headerlink" title="预防抖动的方法"></a>预防抖动的方法</h5><ol>
<li>采用局部置换策略</li>
<li>利用工作集算法防止抖动</li>
<li>利用”L &#x3D; S”准则调节缺页率。L是缺页之间的平均时间，S是平均缺页服务的时间</li>
<li>挂起某些进程</li>
</ol>
<h3 id="分段虚拟存储管理"><a href="#分段虚拟存储管理" class="headerlink" title="分段虚拟存储管理"></a>分段虚拟存储管理</h3><h4 id="基本原理-1"><a href="#基本原理-1" class="headerlink" title="基本原理"></a>基本原理</h4><p>与分页虚拟存储管理原理相同</p>
<p>段表包括：</p>
<ol>
<li>段名</li>
<li>段长</li>
<li>段的基址</li>
<li>存取方式 : 存取属性 可执行 可读 还是允许读&#x2F;写</li>
<li>访问位 </li>
<li>修改位</li>
<li>存在位 : 是否已被调入内存</li>
<li>增补位 ：本段在运行过程中是否做过动态增长</li>
<li>外存地址</li>
</ol>
<h4 id="缺段中断机构"><a href="#缺段中断机构" class="headerlink" title="缺段中断机构"></a>缺段中断机构</h4><p>与缺页中断相同</p>
<p>区别在于段是信息的逻辑单位，不会存在一条指令位于两个段的情况</p>
<h4 id="段的动态连接"><a href="#段的动态连接" class="headerlink" title="段的动态连接"></a>段的动态连接</h4><p>将段的连接推迟到程序运行过程中执行，需要哪一段才把哪段连接到程序地址空间中。</p>
<h4 id="段的共享"><a href="#段的共享" class="headerlink" title="段的共享"></a>段的共享</h4><p>利用段的动态连接可以更好的实现段的共享，一个共享段在不同程序中可以具有不同的段号</p>
<p><strong>可重入代码</strong></p>
<p>又称纯代码，是一种允许多个进程同时访问的代码</p>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>yorn
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="http://wang-chen1119.gitee.io/myblog/2022/10/28/%E8%99%9A%E6%8B%9F%E5%AD%98%E5%82%A8%E5%99%A8%E7%AE%A1%E7%90%86/" title="操作系统学习笔记(六):虚拟存储器管理">http://wang-chen1119.gitee.io/myblog/2022/10/28/虚拟存储器管理/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/myblog/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag"><i class="fa fa-tag"></i> 操作系统</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/myblog/2022/10/28/%E8%99%9A%E5%AD%98%E7%9A%84%E6%A6%82%E5%BF%B5/" rel="prev" title="虚拟存储学习">
                  <i class="fa fa-chevron-left"></i> 虚拟存储学习
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/myblog/2022/10/28/%E7%94%A8%E6%88%B7%E6%8E%A5%E5%8F%A3%E7%AE%A1%E7%90%86/" rel="next" title="操作系统学习笔记(六):虚拟存储器管理">
                  操作系统学习笔记(六):虚拟存储器管理 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yorn</span>
</div>

    </div>
  </footer>

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/myblog/js/comments.js"></script><script src="/myblog/js/utils.js"></script><script src="/myblog/js/motion.js"></script><script src="/myblog/js/next-boot.js"></script><script src="/myblog/js/bookmark.js"></script>

  





  





<script src="/myblog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
